package com.etv.launcher.module;

import android.app.Application;

import androidx.room.Room;

import com.etv.launcher.android.broadcast.GlobalBroadcastReceiver;
import com.etv.launcher.dao.ApplicationInfoDao;

import javax.inject.Singleton;

import dagger.Module;
import dagger.Provides;
import dagger.hilt.InstallIn;
import dagger.hilt.components.SingletonComponent;

/**
 * @author yun
 * @since 2024/3/31 下午1:47
 * <p>
 * 实例化所有需要注入的单例对象
 * 主要是dao的所有对象
 **/
@Module
@InstallIn(SingletonComponent.class)
public abstract class DaoModule {
    @Singleton
    @Provides
    public static GlobalBroadcastReceiver provideGlobalBroadcastReceiver() {
        return new GlobalBroadcastReceiver();
    }


    /**
     * 初始化romm框架
     *
     * @param application
     * @return
     */
    @Singleton
    @Provides
    public static AppDatabase provideAppDatabase(Application application) {
        return Room.databaseBuilder(application, AppDatabase.class, "ETV_DATA_BASE")
                .build();
    }

    /**
     * 应用图标dao
     *
     * @param appDatabase
     * @return
     */
    @Singleton
    @Provides
    public static ApplicationInfoDao provideApplicationInfoDao(AppDatabase appDatabase) {
        return appDatabase.applicationInfoDao();
    }

}
